package dao

import javax.inject.Inject
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

/**
 * Created by yz on 2018/2/27
 */
class HmdbOtherNameKeggDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  def insertAll(rows: Seq[HmdbOtherNameKeggRow]): Future[Unit] = db.run(HmdbOtherNameKegg ++= rows).map(_ => ())

  def deleteAll: Future[Unit] = db.run(HmdbOtherNameKegg.delete).map(_ => ())

  def selectAll(names: Seq[String]) = db.run(HmdbOtherNameKegg.filter(_.cleanName.inSetBind(names)).
    result)

  def selectAll = db.run(HmdbOtherNameKegg.result)

  def updates(rows: Seq[HmdbOtherNameKeggRow]): Future[Unit] = {
    val action = {
      val delete = HmdbOtherNameKegg.delete
      val insertAll = HmdbOtherNameKegg ++= rows
      delete.flatMap(_ => insertAll)
      }.transactionally
    db.run(action).map(_ => ())
  }


}
